package com.cao.controller;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.cao.entity.Test;
import com.cao.entity.Testall;
import com.cao.mapper.TestMapper;
import com.cao.mapper.TestallMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ResponseBody;

import java.net.InetAddress;
import java.net.UnknownHostException;
import java.util.List;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author EN
 * @since 2021-08-26
 */
@Controller
@RequestMapping("testall.do")
public class TestallController {

    @Autowired
    private TestallMapper Mapper;

    //全查询
    @RequestMapping(params = "method=all")
    @ResponseBody
    public List<Testall>  getAll(int page,int begin){
        System.out.println(page+" "+begin);
        System.out.println("bbb");
        InetAddress myhost=null;
        try {
            myhost=InetAddress.getLocalHost();
        } catch (UnknownHostException e) {
            e.printStackTrace();
        }

        //得到被服务器的地址
        String xpath=myhost.getHostAddress();
        QueryWrapper<Testall> queryWrapper =new QueryWrapper<>();
        queryWrapper.orderByDesc("tid");
        Page<Testall> pages=new Page<>(begin,page);
        IPage<Testall> testList=Mapper.selectPage(pages,queryWrapper);

        for (Testall tt:testList.getRecords()
        ) {
            //拼接地址
            tt.setTimg("http://"+xpath+":9000/"+tt.getTimg());
            //System.out.println(tt.getTimg());
        }
        return testList.getRecords();
    }
}

